package model

import (
	"gorm.io/gorm"
	"time"
	"user_service/basic/config"
)

// 用户
type User struct {
	Id        uint           `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	Mobile    string         `gorm:"column:mobile;type:char(11);comment:账号;" json:"mobile"`     // 账号
	Password  string         `gorm:"column:password;type:char(32);comment:密码;" json:"password"` // 密码
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// 用户注册
func (u *User) Create() error {
	return config.DB.Create(&u).Error
}

// 查找用户手机号
func (u *User) GetUserInfoByMobile() error {
	return config.DB.Where("mobile = ?", u.Mobile).Limit(1).Find(&u).Error
}
